package com.bookmanagement.controller.admin;

import com.bookmanagement.entity.Comment;
import com.bookmanagement.result.Result;
import com.bookmanagement.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理端评论管理Controller
 * @author skyjay
 */
@RestController
@RequestMapping("/admin/comment")
public class AdminCommentController {
    
    @Autowired
    private CommentService commentService;
    
    /**
     * 获取所有评论
     */
    @GetMapping("/list")
    public Result<List<Comment>> getAllComments() {
        List<Comment> comments = commentService.getAllComments();
        return Result.success(comments);
    }
    
    /**
     * 获取指定图书的所有评论
     */
    @GetMapping("/book/{bookId}")
    public Result<List<Comment>> getCommentsByBookId(@PathVariable("bookId") Long bookId) {
        List<Comment> comments = commentService.getCommentsByBookId(bookId);
        return Result.success(comments);
    }
    
    /**
     * 删除指定评论
     */
    @DeleteMapping("/{commentId}")
    public Result deleteComment(@PathVariable("commentId") Long commentId) {
        commentService.deleteCommentByAdmin(commentId);
        return Result.success();
    }
}
